import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRootPane;


public class WeatherRadar {

	public volatile JFrame radarMap;
	String APIkey = "0a4529029bcdb510";
	Main delegate;
	RadarUpdater updater;
	
	public WeatherRadar(Main $delegate){
		delegate = $delegate;
		
	}	

	public void launchMap(){
		
	
		
		if(radarMap == null){
			try {
				URL url = new URL("http://api.wunderground.com/api/"+APIkey+"/animatedradar/animatedsatellite/q/FL/Orlando.gif");
		        Icon icon = new ImageIcon(url);
		        JLabel label = new JLabel(icon);
				radarMap = new JFrame("Weather Radar");
				radarMap.getContentPane().add(label);
				radarMap.pack();
				radarMap.setLocation(delegate.getWidth()+delegate.getLocationOnScreen().x - radarMap.getWidth(), delegate.getLocationOnScreen().y);
				radarMap.getGlassPane().setVisible(true);
				radarMap.toBack();
				radarMap.show();
				(new Thread(updater = new RadarUpdater(delegate, radarMap, true))).start();
				
	
			} catch (MalformedURLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}

	public void attach(){
		
	}
	
	public void close() {
		radarMap.setVisible(false);
		radarMap.dispose();
		radarMap = null;
		
	}
	
	
}
